using ProjectSurvivor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;

public class AchievementItem
{
    public string Key { get; private set; }
    public string Name { get; private set; }
    public string Description { get; private set; }
    public bool Unlocked { get; private set; }
    public string  IconName { get; private set; }

    private Func<bool> mCondition;
    private Action<AchievementItem> mOnUnlocked;


    public AchievementItem WithKey(string key)
    {
        Key = key;
        return this;
    }
    public AchievementItem WithName(string name)
    {
        Name = name;
        return this;
    }
    public AchievementItem WithDescription(string Description)
    {
        this.Description = Description;
        return this;
    }
    public AchievementItem WithUnlocked(bool unlocked)
    {
        this.Unlocked = unlocked;
        return this;
    }
    public AchievementItem WithIconName(string IconName)
    {
        this.IconName = IconName;
        return this;
    }
    public AchievementItem WithCondition(Func<bool> condition)
    {
        mCondition = condition;
        return this;
    }
    public AchievementItem WithmOnUnlocked(Action<AchievementItem> OnUnlocked)
    {
        this.mOnUnlocked = OnUnlocked;
        return this;
    }

    public bool ConditionCheck()
    {
        return mCondition();
    }

    public AchievementItem Load(SaveSystem saveSystem)
    {
        Unlocked = saveSystem.LoadBool($"achievement_first_{Key}");
        return this;
    }

    public void UnLocked(SaveSystem saveSystem)
    {
        Unlocked = true;
        saveSystem.SaveBool($"achievement_first_{Key}",true);
        mOnUnlocked?.Invoke(this);
        AchievementSystem.OnAchievementUnlocked.Trigger(this);

    }
}
